<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%@ page import="java.util.List" %>


<!DOCTYPE HTML>
<html>
<head>
<title>检查结果查询</title>
<jsp:include page="scriptAndLink_easyui.jsp"></jsp:include>
<script type="text/javascript" src="<%=basePath%>a2zj/js/json2.js"></script> 
<script type="text/javascript" src="<%=basePath%>a2zj/js/easyui-lang-zh_CN.js"></script> 
<script>
     $(function () {
    	 $('#managerTab').datagrid({
    		singleSelect: true,
		    columns:[[  
		   		{field:'ruleId',title:'规则id',hidden:true},
		   		{field:'projID',title:'项目id',hidden:true},
		   		{field:'projectPackageID',title:'父项目id',hidden:true},
		   		{field:'ruleName',title:'规则名称',width:200},
		   		{field:'procedureName',title:'存储过程名称',hidden:true},
		   		{field:'entType',title:'类型',hidden:true},
		   		{field:'otType',title:'显示列头类型',hidden:true},
		   		{field:'checkContext',title:'检查内容',width:500,
		    		formatter: function(value) {
		    			if(value){
		    				value="<span title='" + value + "'>" + value + "</span>"
		    			}
		    		    return value;
		    		}
		   		}
    		]],
    		rownumbers:true,
    		toolbar: '#tb',
 	        pagination:true,
 	        pageSize:20,
 	        pageList:[20,30,50]
		}); 
    	//质检项目tree
        buildQualityTree();
/*     	$("#yearMon").datebox({
				editable : false,
				formatter: function (date) {return date.format("yyyy-MM-dd"); }
         })
    	$("#yearMon").datebox("setValue",new Date().format("yyyy-MM-dd")); */
    });
    var entityType;
    function queryData(){
    	//var queryDate = $("#yearMon").datebox("getValue");
   	    var selectedRows = $('#managerTab').datagrid('getSelections');
   	    if(selectedRows.length==0){
   		   alert("请选择要查询的规则！")
   		   return;
   	    }
	   	$('#tbl_queryReport').datagrid({
	   		    //fit: true,
	   		    singleSelect: true,
	   		    pageNumber:1,
	   		    url:"<%=basePath%>zj/zjProcedureManager.do?method=getQueryAllRuleLog&otType="+selectedRows[0].otType+"&ruleId="+selectedRows[0].ruleId+"&newDate=" + (new Date()).getTime(),
			    columns:[[
			   		{field:'RULE_ID',title:'规则id',hidden:true},
			   		{field:'ENTITY_NAME',title:'机构名称',width:150,
			    		formatter: function(value) {
			    			if(value){
			    				value="<span title='" + value + "'>" + value + "</span>"
			    			}
			    		    return value;
			    		}
			   		},
			   		{field:'ENTITY_NAME_SEN',title:'下级机构(或井)',width:150,
			    		formatter: function(value) {
			    			if(value){
			    				value="<span title='" + value + "'>" + value + "</span>"
			    			}
			    		    return value;
			    		}
			   		},
			   		{field:'CHEAK_DATE',title:'检查时间',width:130},
			   		{field:'YEAR_MON',title:'数据时间',width:100},
			   		{field:'CHECK_RESULT',title:'校验结果',width:100,
			   			formatter: function(value) {
			    		    if(value=='不合格'){
			    		    	return '<span style="color:red;">'+value+'</span>';
			    			}else if(value=='合格'){
			    				return '<span style="color:green;">'+value+'</span>';
			    			}
			    		    return value;
			    		}
			   		},
			   		{field:'ORG_LEVEL',title:'机构级别',hidden:true},
			   		{field:'RESULT_DESC',title:'结果描述',width:500,
			    		formatter: function(value) {
			    			if(value){
			    				value="<span title='" + value + "'>" + value + "</span>"
			    			}
			    		    return value;
			    		}
			   		},
			   	    {field:'VP_NAME',title:'检查机构',width:500}		   		
	 		    ]],
	 		    rownumbers:true,
	 	        pagination:true,
	 	        toolbar: '#div_ruleExcelExportToolbar',
	 	        pageSize:20,
	 	        pageList:[20,30,50],
		        onClickRow:function(index, row){
		            $("#result_desc_span").html(row.RESULT_DESC);		
		        },
		        onDblClickRow: function (rowIndex, rowData) {
		        	if(rowData.CHECK_RESULT=='合格'){
		        		return;
		        	}
		        	queryDetailData(rowData.RULE_ID,rowData.ENTITY_NAME_SEN,selectedRows[0].otType,rowData.ORG_LEVEL); 
		        }
/* 		        ,
		        rowStyler:function(index,row){
		        	if(row.CHECK_RESULT=='不合格'){
		        		 return 'background-color:pink;';
		        	}
		        }  */
		}); 

   	    if(selectedRows[0].otType=='2'){
   	    	var option = $('#tbl_queryReport').datagrid("getColumnOption", "ENTITY_NAME")
   	        option.title = "区块名称";
   	    	var option1 = $('#tbl_queryReport').datagrid("getColumnOption", "ENTITY_NAME_SEN")
   	    	option1.title = "下级区块(或井)";
   	    	$('#tbl_queryReport').datagrid();
   	    }
       
 		$('#div_queryWin').dialog({
			title : '质检结果查看',
			closed : false,
			onClose: function () {
				$("#tbl_queryReport").datagrid('loadData', { total: 0, rows: [] });
				$("#result_desc_span").html("");
	        }
		});
    }
    
    function queryDetailData(ruleId,entityName,otType,orgLevel){
	   	$('#tbl_queryDetailReport').datagrid({
	   		    //fit: true,
	   		    pageNumber:1,
	   		    url:"<%=basePath%>zj/zjProcedureManager.do?method=getQueryAllRuleLog&logType=Detail&orgLevel="+orgLevel+"&otType="+otType+"&entityName="+encodeURI(entityName)+"&ruleId="+ruleId+"&newDate=" + (new Date()).getTime(),
	   		    singleSelect: true,
			    columns:[[
			   		{field:'RULE_ID',title:'规则id',hidden:true},
			   		{field:'ENTITY_NAME',title:'机构名称',width:150,
			    		formatter: function(value) {
			    			if(value){
			    				value="<span title='" + value + "'>" + value + "</span>"
			    			}
			    		    return value;
			    		}
			   		},
			   		{field:'ENTITY_NAME_SEN',title:'下级机构(或井)',width:150,
			    		formatter: function(value) {
			    			if(value){
			    				value="<span title='" + value + "'>" + value + "</span>"
			    			}
			    		    return value;
			    		}
			   		},
			   		{field:'CHEAK_DATE',title:'检查时间',width:130},
			   		{field:'YEAR_MON',title:'数据时间',width:100},
			   		{field:'CHECK_RESULT',title:'校验结果',width:100,
			   			formatter: function(value) {
			    		    if(value=='不合格'){
			    		    	return '<span style="color:red;">'+value+'</span>';
			    			}else if(value=='合格'){
			    				return '<span style="color:green;">'+value+'</span>';
			    			}
			    		    return value;
			    		}
			   		},
			   		{field:'ORG_LEVEL',title:'机构级别',hidden:true},
			   		{field:'RESULT_DESC',title:'结果描述',width:500,
			    		formatter: function(value) {
			    			if(value){
			    				value="<span title='" + value + "'>" + value + "</span>"
			    			}
			    		    return value;
			    		}
			   		},
			   	    {field:'VP_NAME',title:'检查机构',width:500}  		
	 		    ]],
	 		    rownumbers:true,
	 	        pagination:true,
	 	        pageSize:20,
	 	        pageList:[20,30,50],
		        onClickRow:function(index, row){
		            $("#result_detail_desc_span").html(row.RESULT_DESC);		
		        },
		        onDblClickRow: function (rowIndex, rowData) {
		        	if(rowData.CHECK_RESULT=='合格'){
		        		return;
		        	}
		        	queryDetailData(rowData.RULE_ID,rowData.ENTITY_NAME_SEN,otType,rowData.ORG_LEVEL); 
		        }
/* 		        ,
		        rowStyler:function(index,row){
		        	if(row.CHECK_RESULT=='不合格'){
		        		 return 'background-color:pink;';
		        	}
		        }  */
		}); 
   	    if(otType=='2'){
   	    	var option = $('#tbl_queryDetailReport').datagrid("getColumnOption", "ENTITY_NAME")
   	    	var option1 = $('#tbl_queryDetailReport').datagrid("getColumnOption", "ENTITY_NAME_SEN")
   	        option.title = "区块名称";
   	    	option1.title = "下级区块(或井)";
   	    	$('#tbl_queryDetailReport').datagrid();
   	    }
 		$('#div_queryDetailWin').dialog({
			title : '质检详细结果查看',
			closed : false,
			onClose: function () {
				$("#tbl_queryDetailReport").datagrid('loadData', { total: 0, rows: [] });
				$("#result_detail_desc_span").html("");
	        }
		});
    }
    function flowManageCancel(){
		$('#div_queryWin').dialog({closed : true});
    }
    
  	Date.prototype.format = function (fmt) {
 	    var o = {
 	        "M+": this.getMonth() + 1, //月份 
 	        "d+": this.getDate(), //日 
 	        "h+": this.getHours(), //小时 
 	        "m+": this.getMinutes(), //分 
 	        "s+": this.getSeconds(), //秒 
 	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
 	        "S": this.getMilliseconds() //毫秒 
 	    };
 	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
 	    for (var k in o)
 	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
 	    return fmt;
 	}     
     //获取质检项目目录树
     var selectedProjectId;
     function buildQualityTree(){
     	$("#treeDemo").tree({
         	url : "<%=basePath%>zj/zjProcedureManager.do?method=buildQualityTree&newDate=" + (new Date()).getTime(),
         	animate:true,//定义当节点展开折叠时是否显示动画效果
         	onLoadSuccess:function(){
         		//关闭遮罩
     				$('#loading-mask').fadeOut();
         	},
     		onBeforeExpand:function(node){
     			var isParent = node.attributes.isParent;
     			if(isParent){
     				var childrenNode = $("#treeDemo").tree('getChildren',node.target);
     				if(childrenNode.length === 0){//当前节点下没有子节点时,不展开
     					return false;
     				}
     			}
     		},
         	onClick:function(node){
         		selectedProjectId = node.id;
         		var isParent = node.attributes.isParent;
     			if(isParent){
     				$("#treeDemo").tree('toggle',node.target);
     			}else{//叶子节点（展现该质检项目下的质检规则）
     				var parentNode = $(this).tree('getParent',node.target);
     				initRuleGrid(node.id,parentNode.id);
     			}
         	},
         	onLoadError:function(XMLHttpRequest, textStatus, errorThrown){
         		$.messager.alert('消息提示','请求数据失败，请检查服务器是否为开启状态!'+textStatus);
     			return false;
         	}
         });
     }

 	function initRuleGrid(prjId,projectPackageID){
		if(!prjId){
			prjId = "";
		}
		//var paramData = "{prjId:'" + prjId+"'}";
		$("#managerTab").datagrid('loadData', { total: 0, rows: [] });
			$("#managerTab").datagrid({
			queryParams : {},
			url:"<%=basePath%>zj/zjProcedureManager.do?method=getRuleInfo&prjId="+prjId+"&projectPackageID="+projectPackageID+"&newDate=" + (new Date()).getTime()
		});
	}

    function exportExcel(){
   	    var selectedRows = $('#managerTab').datagrid('getSelections');
   	    expExcelForm.ruleId.value=selectedRows[0].ruleId;
   	    expExcelForm.submit();
    }
    
    
    function createInput(name, value) {
        var inputElement = document.createElement("input");
        inputElement.type = "hidden";
        inputElement.name = name;
        if (value != null) {
            inputElement.value = value;
        }
        return inputElement;
    }
 
    function postForm(url) {
        // 创建表单
        var formElement = document.createElement("form");
        formElement.action = url;
        formElement.method = "post";
        // 打开新标签
        formElement.target = '_blank';
        formElement.style.display = "none";
        document.body.appendChild(formElement);
        formElement.submit();
        return formElement;
    }
     
    </script>
</head>
<body class="easyui-layout" style="width: auto; height: 700px">
<html:form action="/zj/zjProcedureManager">
	<input type="hidden" name="method" value="exportExcel"/>
  	<input type="hidden" name="ruleId" value=""/>
	<div id="loading-mask" style="position:absolute;top:0px; left:0px; width:100%; height:100%; background:#D2E0F2; z-index:20000">
	    <div id="pageloading" style="position:absolute; top:50%; left:50%; margin:-120px 0px 0px -120px; text-align:center;  border:2px solid #8DB2E3; width:200px; height:40px;  font-size:14px;padding:10px; font-weight:bold; background:#fff; color:#15428B;"> 
	    	正在加载,请稍候...
	    </div>
	</div>
	<div data-options="region:'west' " style="width: 300px">
		<ul id="treeDemo">
		</ul>
	</div>
	<div data-options="region:'center', border:false"
		style="border-color: #ccc; width: 100%; height: 100%;">
		<table id="managerTab" class="easyui-datagrid"
			style="width: auto; height: 800px" fit="true"></table>
	</div>
	<div id="tb" style="display: none;">
		<table border="0">
		   <tr>
<!-- 			 <td style="text-align:right;font-size:12px;vertical-align:middle;">查询日期:</td>
			 <td style="width:100px;">
				 <input id="yearMon" type="text" class="Wdate" style="border-radius: 5px; padding-left:5px; width: 100px;"/>
			 </td> -->
			 <td>
				 <a href="javascript:queryData();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true"  id="btn">查询</a>
			 </td>
		   </tr>
		</table>
	</div>
	  <div id="div_queryWin" class="easyui-dialog"	style="width: 900px; height: 500px;" data-options="closed:true, modal:true">
			<div style="height: 85%;width: 100%">
					<table id="tbl_queryReport" style="width: auto; height: 500px" fit="true"></table>
			</div>
		   <div style="height: 15%;width: 100%">
		      <span id="result_desc_span" style="margin-top: 5px;margin-left: 5px;font-size: 14px;">点击行数据时，显示详情描述信息</span>
	      </div>	
	      <div id="div_ruleExcelExportToolbar" style="display: none;" >
		  <table>
			<tr>
				<td><a href="javascript:exportExcel();" id="btn_ruleGrid_excelExport" class="easyui-linkbutton" data-options="iconCls:'icon-down',plain:true" >excel导出</a></td>
			</tr>
		</table>
	</div>
	 </div>	 
	 	  <div id="div_queryDetailWin" class="easyui-dialog"	style="width: 900px; height: 500px;"  data-options="closed:true, modal:true, left: 80, top:50">
			<div style="height: 85%;width: 100% ">
					<table id="tbl_queryDetailReport" style="width: auto; height: 500px" fit="true"></table>
			</div>
		   <div style="height: 15%;width: 100%">
		      <span id="result_detail_desc_span" style="margin-top: 5px;margin-left: 5px;font-size: 14px;">点击行数据时，显示详情描述信息</span>
	      </div>	
	 </div>
	 </html:form>
</body>
</html>